package com.chapala.interviewquestions;

import com.thoughtworks.xstream.XStream;



public class Anagram {
   public boolean isAnagram(String firstStr,String secondStr){
	   if(firstStr==null||secondStr==null){
		   return false;
	   }
	   if(firstStr.length()!=secondStr.length()){
		   return false;
	   }
	   int[] noOfCharsFirstStr = new int[256];
	   int[] noOfCharsSecondStr = new int[256];
	   
	   for(int i=0;i<firstStr.length();i++){
		   
		   noOfCharsFirstStr[firstStr.charAt(i)-'a'] = noOfCharsFirstStr[firstStr.charAt(i)-'a'] + 1;  
		   noOfCharsSecondStr[secondStr.charAt(i)-'a'] = noOfCharsSecondStr[secondStr.charAt(i)-'a']+1;
	   }
	   System.out.println("firstArray"+new XStream().toXML(noOfCharsFirstStr));
	   System.out.println("secondArray"+new XStream().toXML(noOfCharsSecondStr));
	   for(int j=0;j<firstStr.length();j++){
		   if(noOfCharsFirstStr[j]!=noOfCharsSecondStr[j])
			   return false;
	   }
	return true;
	   
   }
   
   public static void main(String[] args) {
	   //System.out.println("isAnagram"+new Anagram().isAnagram("aaaaa", "bbbbb"));
	   //System.out.println("isAnagram"+new Anagram().isAnagram("bhuvi", "murali"));
		System.out.println("isAnagram"+new Anagram().isAnagram("khris", "rishk"));
	}
	
	
}
